package com.hk.commons;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class DataUtil {

	 
	/**
	 * 将百分比转换为小数
	 * @param data , String 类型的百分比
	 * @return BigDecimal 类型的小数
	 */
	public static BigDecimal percentageToDecimal(String data) {
		BigDecimal newDate = new BigDecimal(data.replace("%", ""))
				.divide(new BigDecimal(100));
		return newDate;
	}
	
	
	
	/**
	 * 将百分比转换为小数
	 * @param dayString
	 * @return
	 */
	public static String decimalToPercentage(BigDecimal data) {
		DecimalFormat df = new DecimalFormat("0.00");
		
		String newDateStr = null;
		BigDecimal newDate = data.multiply(new BigDecimal(100));
		newDateStr = df.format(newDate) + "%";
		
		return newDateStr;
	}
	
	/**
	 * 加密用户姓名
	 * @param name
	 * @return
	 */
	public static String getEncryptRealName(String name) {
		 String str = "";
		 if(StringHelper.isNotEmpty(name)){
			 if(name.length() == 2){
				 str = DataMasking.getMaskingData(name, 1);
			 }else if (name.length() == 3){
				 str = DataMasking.getMaskingData(name, 1, 1);
			 }else{
				 str = DataMasking.getMaskingData(name, 2);
			 }
		 }
		return str;
	}
	
	
	public static String getBetweenEncryptRealName(String name) {
		 String str = "";
		 if(StringHelper.isNotEmpty(name)){
			 if(name.length() == 2){
				 str = DataMasking.getMaskingData(name, 1);			
			 }else{
				 str = DataMasking.getMaskingData(name, 1, 1);
			 }
		 }
		return str;
	}
	
	/**
	 * 加密用户手机号
	 * @param phone
	 * @return
	 */
	public static String getEncryptPhoneNum(String phone){
		String str = "";
		if(StringHelper.isNotEmpty(phone)){
			str = DataMasking.getMaskingData(phone, 3, 4) ;
		}
		return str;
	}
}
